/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-12-23
 * Time:16:03
 */

class Money implements Cloneable{
    public double money = 12.5;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Preson implements Cloneable{
    public String name = "xiebang";
    public Money money = new Money();
    public int a = 10;
//    @Override
//    public String toString() {
//        return "Preson{" +
//                "name='" + name + '\'' +
//                '}';
//    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
        Preson presonClone = (Preson) super.clone();
        presonClone.money = (Money) this.money.clone();
        return presonClone;
    }
}
public class TestDemo2 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Preson preson = new Preson();
        Preson preson1 = (Preson) preson.clone();
        System.out.println(preson.money.money);
        System.out.println(preson1.money.money);
        preson1.money.money = 99.9;
        System.out.println(preson.money.money);
        System.out.println(preson1.money.money);

    }
    public static void main2(String[] args) throws CloneNotSupportedException {
        Preson preson = new Preson();
        Preson preson1 = (Preson) preson.clone();
        System.out.println(preson.a);
        System.out.println(preson1.a);
        preson1.a = 99;
        System.out.println(preson1.a);//99
        System.out.println(preson.a);//10
        //这就是深拷贝,拷贝内容的改变不会改变被拷贝的内容
    }
    public static void main1(String[] args) throws CloneNotSupportedException{
        Preson preson = new Preson();
        System.out.println(preson);
        Preson preson1 = (Preson) preson.clone();
        System.out.println(preson1);
    }
}
